package cn.linkpower.aop;

import javax.servlet.http.HttpServletRequest;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;


@Aspect
@Component
public class TokenAspectJMethod {
	/**
	 * 方式二：不采取注解的方式，使用全局方法适配完成
	 */
	@Pointcut("execution(public * cn.linkpower.controller2..*.*(..))")
	public void checkMethod() {
		
	}
	
	@Before("checkMethod()")
	public void beforeTest(JoinPoint joinPoint) {
		ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
		HttpServletRequest request = requestAttributes.getRequest();
		String method = request.getMethod();
		System.out.println("before---------method ----"+method);
	}
	
	@After("checkMethod()")
	public void afterTest(JoinPoint joinPoint) {
		ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
		HttpServletRequest request = requestAttributes.getRequest();
		System.out.println("after---------method ----");
	}
}
